<template>
    <div>
        <!-- 顶部滑动区域 -->
        <div class="mui-content">
			<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item', item.id == 0? 'mui-active': '']"  v-for="item in category" :key="item.id" @click="getImg(item.id)">
							{{ item.name }}
						</a>
					</div>
				</div>

			</div>
		</div>
        
        <!-- 图片列表展示 -->
        <ul class="photo-list">
            <routerLink v-for="item in imgList" :key="item.id" :to="'/home/photoinfo?id='+item.id" tag="li">
                <img v-lazy="item.pic">
                <div class="imgInfo">
                    <h3>{{ item.name }}</h3>
                    <p>{{ item.characteristic }}</p>
                </div>
            </routerLink>
        </ul>

    </div>
</template>

<script>
    // 导入mui js文件
    import mui from '../../lib/mui/js/mui.js'
    import querystring from 'querystring'
    
    export default {
        data() {
            return {
                category: '',    // 所有分类
                imgList: []    //分类商品列表
            }
        },
        created() {
            this.getCategory()
            this.getImg(0)  //默认获取全部分类商品
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        }, 
        methods: {
            getCategory() {
                this.$http.get('/shop/goods/category/all').then( (res) => {
                    if(res.data.code === 0) {
                        res.data.data.unshift({id: 0, name: '全部'})
                        this.category = res.data.data
                    }
                } )
            },
            getImg(id) {
                this.$http.post('/shop/goods/list', querystring.stringify({
                    categoryId: id==0?'':id
                })).then( (res) => {
                    if(res.data.code === 0) {
                        this.imgList = res.data.data
                    }
                })
            }
        }, 
    }
</script>

<style lang="scss" scoped>
*{ 
    // 谷歌浏览器，提高用户滑动流畅度，启用手指垂直平滑 
    touch-action: pan-y;    
} 
img{
    vertical-align: middle;
}
.photo-list{
    width: 95%;
    padding: 0;
    margin: 0 auto;
    li{
        list-style: none;
        position: relative;
        background: #ccc;
        margin-bottom: 10px;
        padding: 0;
        text-align: center;
        position: relative;
        img{
            width: 100%;
        }
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: 0 auto;
        }
        .imgInfo{
            position: absolute;
            left: 0;
            bottom: 0;
            background-color: rgba(0,0,0,.5);
            color: #fff;
            text-align-last: left;
            padding: 5px 0;
            width: 100%;
            h3{
                font-size: 14px;
                padding-left: 10px;
            }
            p{
                font-size: 12px;
                padding: 0 10px;
                color: #fff;
                line-height: 14px;
                text-align: justify;
                margin-bottom: 0;
            }
        }
    }
}



</style>